package com.doudi.sessionid;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import redis.clients.jedis.Jedis;

public class Push2Redis {
	public void readFromTxtEachLine(String filePath, int startLine, int endLine) throws IOException {
		File file = new File(filePath);
		BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
		BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "utf-8"), 5 * 1024 * 1024);// ��5M�Ļ����ȡ�ı��ļ�

		Jedis jedis = new Jedis("127.0.0.1", 6379);

		String line = "";
		int count = startLine;

		// uid_sessionkey_student.txt共5000000数据
		// 175486 73d672b476b7bc8cb94bb3b039deee76
		String[] strArr = new String[2];
		while ((line = reader.readLine()) != null && count <= endLine) {
			System.out.println(count + "行，数据" + line);
			strArr = line.replace("\t", " ").split(" ");
			// System.out.println(strArr[0]);
			// System.out.println(strArr[1]);
			jedis.set(strArr[1], strArr[0]);
			count++;
		}
	}

	public static void main(String[] args) throws IOException {
		String filePath = args[0];
		int startLine = Integer.valueOf(args[1]);
		int endLine = Integer.valueOf(args[2]);
		new Push2Redis().readFromTxtEachLine(filePath, startLine, endLine);
	}
}
